package com.neusoft.yuejian_6.adapter;

import android.content.Context;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.neusoft.yuejian_6.R;
import com.neusoft.yuejian_6.activity.ClassInfoActivity;
import com.neusoft.yuejian_6.javabean.Classes;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.neusoft.yuejian_6.base.Constant.PHOTO_URL;


public class ClassListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater1;

    public ClassListAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater1 = LayoutInflater.from(mContext);
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Classes entity = (Classes) mDataList.get(position);
        if (null == entity)
            return;
        //绑定数据
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.class_name.setText(entity.getClass_name());
        //viewHolder.club_name.setText(entity.getClub_name());
        // System.out.printf("activity_name");
       // viewHolder.price.setText("￥"+entity.getTrain_price()+ "元");
        final String class_pic =PHOTO_URL+entity.getClass_pic();

        Picasso.with(mContext).load(class_pic).into(viewHolder.class_pic);
        if(viewHolder.class_pic.getDrawable()==null){
            viewHolder.class_pic.setImageResource(R.drawable.no_pic);
        }
        //点击item跳转
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle=new Bundle();
                bundle.putInt("class_id",entity.getClass_id());
                bundle.putInt("club_id",entity.getClub_id());
                bundle.putString("class_name",entity.getClass_name());
                bundle.putInt("class_price",entity.getClass_price());
                bundle.putString("class_pic",entity.getClass_pic());
                bundle.putString("class_teacher",entity.getClass_teacher());
                bundle.putString("class_phone",entity.getClass_phone());
                bundle.putString("class_time",entity.getClass_time());
                bundle.putString("class_address",entity.getClass_address());
                bundle.putString("class_intro",entity.getClass_intro());
                Intent intent=new Intent(mContext, ClassInfoActivity.class);
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });


    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //创建ViewHolder
        View v = mLayoutInflater1.from(parent.getContext()).inflate(R.layout.cardview_class, parent, false);
        return new ViewHolder(v);

    }

    //自定义的V
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView class_pic;
        TextView class_name,club_name;

        public ViewHolder(View itemView) {
            super(itemView);
            class_name = (TextView) itemView.findViewById(R.id.Classlist_name);
            class_pic = (ImageView) itemView.findViewById(R.id.Classlist_pic);
            //club_name= (TextView) itemView.findViewById(R.id.club_name);
           // price= (TextView) itemView.findViewById(R.id.price);
        }
    }
}
